package com.hehao.java_basic.design_mode.behaviour.strategy.practice;

import com.hehao.common.entiy.Receipt;

import java.util.List;

/**
 * @author Damon
 * @date 2023/6/29
 */
public class StrategyClient {
    public static void main(String[] args) {
        List<Receipt> receipts = Receipt.generateReceiptList();
        ReceiptStrategyContext context = new ReceiptStrategyContext();
        receipts.forEach(receipt -> {
            //策略工厂获取策略
            IReceiptHandleStrategy strategy = ReceiptHandleStrategyFactory.getReceiptHandleStrategyByMap(receipt.getType());
            //赋值上下文
            context.setReceiptHandleStrategy(strategy);
            //通过上下文执行具体策略的方法
            context.handleReceipt(receipt);
        });
    }
}
